<html>
<head><meta charset="utf-8"><title>get a module from a `self` param · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html">get a module from a `self` param</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="235014011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235014011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235014011">(Apr 17 2021 at 20:10)</a>:</h4>
<p>Hey, I'm working on <a href="https://github.com/rust-analyzer/rust-analyzer/issues/8555">https://github.com/rust-analyzer/rust-analyzer/issues/8555</a> - and I'm not sure how to a reference to the current <code>Module</code> the file refers to. Is there a convenient way to get this?</p>



<a name="235014115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235014115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235014115">(Apr 17 2021 at 20:12)</a>:</h4>
<p>I think the simplest way is to go with <code>sema.scope(syntax_node).module()</code></p>



<a name="235014125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235014125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235014125">(Apr 17 2021 at 20:12)</a>:</h4>
<p>Or I guess a way to go from a <code>hir::Type</code> to a <code>Module</code>. I'm trying to do a non-local way to get from a given variable to an <code>impl</code> block</p>



<a name="235014133"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235014133" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235014133">(Apr 17 2021 at 20:12)</a>:</h4>
<p><span class="user-mention" data-user-id="300586">@Lukas Wirth</span> ohh, I'll give that a shot!</p>



<a name="235014768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235014768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235014768">(Apr 17 2021 at 20:23)</a>:</h4>
<p>I guess part of what I'm trying to do is deprecate all uses of <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/utils.rs#L310-L318">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/utils.rs#L310-L318</a>, in favor of going through the hir db</p>



<a name="235014825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235014825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235014825">(Apr 17 2021 at 20:24)</a>:</h4>
<p>"list me all impl blocks associated with this type, so I can pick the first one" is something which should be answerable</p>



<a name="235015005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015005">(Apr 17 2021 at 20:27)</a>:</h4>
<p>It appears to be somewhat difficult right now to go from "here's a value" to "here are the impl blocks associated with that value's type"</p>



<a name="235015068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015068">(Apr 17 2021 at 20:28)</a>:</h4>
<p>(Mostly just typing stuff out as I go, if anyone knows of better approaches / prior art on this, please do chime in!)</p>



<a name="235015094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015094">(Apr 17 2021 at 20:29)</a>:</h4>
<p>There is infra to query all impls for a type, you could pick one of those then and map that back to the source node</p>



<a name="235015102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015102">(Apr 17 2021 at 20:29)</a>:</h4>
<p>(deleted)</p>



<a name="235015201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015201">(Apr 17 2021 at 20:30)</a>:</h4>
<p><a href="https://github.com/Veykril/rust-analyzer/blob/58a6ec549d638455f5b5447bbbc174993e51e288\crates\hir\src\lib.rs#L1571">https://github.com/Veykril/rust-analyzer/blob/58a6ec549d638455f5b5447bbbc174993e51e288\crates\hir\src\lib.rs#L1571</a></p>



<a name="235015235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015235">(Apr 17 2021 at 20:31)</a>:</h4>
<p>You'd have to filter out trait impls though since you dont want those i imagine</p>



<a name="235015240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015240">(Apr 17 2021 at 20:32)</a>:</h4>
<p><em>oh</em> -- yeah that's a good idea!</p>



<a name="235015299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015299">(Apr 17 2021 at 20:32)</a>:</h4>
<p>Then there is the <code>HasSource</code> tree that maps defs back to their source node if they have one</p>



<a name="235015306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015306">(Apr 17 2021 at 20:32)</a>:</h4>
<p>which is implemented for <code>Impl</code> so that should work</p>



<a name="235015600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015600">(Apr 17 2021 at 20:37)</a>:</h4>
<p>oh, yay! -- I successfully got an impl block!</p>



<a name="235015605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235015605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235015605">(Apr 17 2021 at 20:37)</a>:</h4>
<p>okayyyyyyy, let's gooooo</p>



<a name="235016966"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235016966" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235016966">(Apr 17 2021 at 20:58)</a>:</h4>
<p><span class="user-mention" data-user-id="300586">@Lukas Wirth</span> is there a canonical way to go from a hir type to an ast type?</p>



<a name="235016986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235016986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235016986">(Apr 17 2021 at 20:58)</a>:</h4>
<p>Uuh</p>



<a name="235016988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235016988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235016988">(Apr 17 2021 at 20:58)</a>:</h4>
<p>I've got the <code>hir::Impl</code> but I want its position in the AST (<code>ast::Impl</code>)</p>



<a name="235016993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235016993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235016993">(Apr 17 2021 at 20:58)</a>:</h4>
<p>not sure if this question makes sense?</p>



<a name="235016995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235016995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235016995">(Apr 17 2021 at 20:58)</a>:</h4>
<p>going from hir::Impl to ast::Impl is simple</p>



<a name="235016998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235016998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235016998">(Apr 17 2021 at 20:58)</a>:</h4>
<p>There is a trait for that <code>HasSource</code></p>



<a name="235017024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235017024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235017024">(Apr 17 2021 at 20:59)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">HasSource</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">type</span> <span class="nc">Ast</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">source</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">db</span>: <span class="kp">&amp;</span><span class="nc">dyn</span><span class="w"> </span><span class="n">HirDatabase</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nb">Option</span><span class="o">&lt;</span><span class="n">InFile</span><span class="o">&lt;</span><span class="bp">Self</span>::<span class="n">Ast</span><span class="o">&gt;&gt;</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="235017091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235017091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235017091">(Apr 17 2021 at 21:00)</a>:</h4>
<p>so you should be able to just go with <code>impl_.source(db)</code> and get your ast::Impl out of that</p>



<a name="235017488"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235017488" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235017488">(Apr 17 2021 at 21:01)</a>:</h4>
<p>oh yay, thank you!</p>



<a name="235023048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235023048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235023048">(Apr 17 2021 at 22:16)</a>:</h4>
<p>gah, I managed to get <code>hir::Impl::all_for_type</code> to work, but now it's returning empty lists again -- not sure what I changed</p>



<a name="235023051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235023051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235023051">(Apr 17 2021 at 22:16)</a>:</h4>
<p>think it's time to call it a day, heh</p>



<a name="235023068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235023068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235023068">(Apr 17 2021 at 22:17)</a>:</h4>
<p>pushed the branch <a href="https://github.com/rust-analyzer/rust-analyzer/compare/master...yoshuawuyts:whats-a-method-to-a-method-call">https://github.com/rust-analyzer/rust-analyzer/compare/master...yoshuawuyts:whats-a-method-to-a-method-call</a> in case I don't get around to finishing this up</p>



<a name="235024500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235024500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235024500">(Apr 17 2021 at 22:43)</a>:</h4>
<p>I think it might be returning nothing when your type is a reference,  you would have to strip the type of references before asking for impls first.</p>



<a name="235024565"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235024565" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235024565">(Apr 17 2021 at 22:44)</a>:</h4>
<p>If I recall correctly impl search doesn't like references(for some valid reasons I don't remember right now)</p>



<a name="235024941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235024941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235024941">(Apr 17 2021 at 22:52)</a>:</h4>
<p><span class="user-mention" data-user-id="300586">@Lukas Wirth</span> what do you mean by "stripping it of references" -- cast it somehow?</p>



<a name="235024988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235024988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235024988">(Apr 17 2021 at 22:52)</a>:</h4>
<p>ah no, I mean the type the <code>hir::Type</code> represents</p>



<a name="235024994"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235024994" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235024994">(Apr 17 2021 at 22:52)</a>:</h4>
<p>if that is a reference type that it represetns it probably doesnt work</p>



<a name="235024998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235024998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235024998">(Apr 17 2021 at 22:52)</a>:</h4>
<p>let me check the api quickly</p>



<a name="235025020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025020">(Apr 17 2021 at 22:53)</a>:</h4>
<p>oh whattttt</p>



<a name="235025022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025022">(Apr 17 2021 at 22:53)</a>:</h4>
<p>that worked?</p>



<a name="235025027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025027">(Apr 17 2021 at 22:53)</a>:</h4>
<p>I changed the signature from <code>&amp;self</code> to <code>self</code> and <em>swoosh</em> it's working again</p>



<a name="235025082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025082">(Apr 17 2021 at 22:54)</a>:</h4>
<p>Ye okay then my thought was correct</p>



<a name="235025092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025092">(Apr 17 2021 at 22:54)</a>:</h4>
<p>I think we index impls by non-reference types for simplicity</p>



<a name="235025093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025093">(Apr 17 2021 at 22:54)</a>:</h4>
<p>oh wow, would not have guessed that this was the issue -- been at this for a good while now haha</p>



<a name="235025095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025095">(Apr 17 2021 at 22:54)</a>:</h4>
<p>Ye its a bit weird <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="235025099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025099">(Apr 17 2021 at 22:55)</a>:</h4>
<p>so you wanna strip the references of the hir type</p>



<a name="235025107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025107">(Apr 17 2021 at 22:55)</a>:</h4>
<p>yes please!</p>



<a name="235025109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025109">(Apr 17 2021 at 22:55)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">std</span>::<span class="n">iter</span>::<span class="n">successors</span><span class="p">(</span><span class="nb">Some</span><span class="p">(</span><span class="n">ty</span><span class="p">.</span><span class="n">clone</span><span class="p">()),</span><span class="w"> </span><span class="o">|</span><span class="n">ty</span><span class="o">|</span><span class="w"> </span><span class="n">ty</span><span class="p">.</span><span class="n">remove_ref</span><span class="p">())</span><span class="w"></span>
<span class="w">        </span><span class="p">.</span><span class="n">last</span><span class="p">()</span><span class="w"></span>
</code></pre></div>
<p>something like this</p>



<a name="235025129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025129">(Apr 17 2021 at 22:55)</a>:</h4>
<p>should do the trick, we should add a method for this to hir::Type at some point I think since this is done in multiple locations by now</p>



<a name="235025211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025211">(Apr 17 2021 at 22:56)</a>:</h4>
<p>Feel free to ask and ping if you get stuck on things like these <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>



<a name="235025217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025217">(Apr 17 2021 at 22:56)</a>:</h4>
<p>Dont mind helping if I'm online that is</p>



<a name="235025222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025222">(Apr 17 2021 at 22:56)</a>:</h4>
<p>much appreciated!</p>



<a name="235025238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025238">(Apr 17 2021 at 22:57)</a>:</h4>
<p>I guess I got angry-stuck on this one -- I had it working once, so I could get it working again :P</p>



<a name="235025239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025239">(Apr 17 2021 at 22:57)</a>:</h4>
<p>I guess this is the problem with undocumented functions that have weird special case behaviours <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="235025248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025248">(Apr 17 2021 at 22:57)</a>:</h4>
<p>Been there</p>



<a name="235025289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025289">(Apr 17 2021 at 22:58)</a>:</h4>
<p>it's rarely fruitful though -- appreciate the offer to help, and will def opt to do that next time <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="235025551"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235025551" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235025551">(Apr 17 2021 at 23:03)</a>:</h4>
<p>Getting into RA's codebase takes a bit of time, but once you got a grasp of things its a pleasure to work with in my opinion <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>



<a name="235026532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235026532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235026532">(Apr 17 2021 at 23:20)</a>:</h4>
<p>yeah, RA is so well structured! -- I've worked on a few compiler projects before, and RA certainly is among the easiest to work on</p>



<a name="235026578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235026578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235026578">(Apr 17 2021 at 23:21)</a>:</h4>
<p>just got my first test passing for this assist btw -- think it's time to call it a day</p>



<a name="235026580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235026580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235026580">(Apr 17 2021 at 23:21)</a>:</h4>
<p>goodnight, and thanks for the help!</p>



<a name="235026662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235026662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235026662">(Apr 17 2021 at 23:23)</a>:</h4>
<p>No problem and good night <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="235056613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235056613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235056613">(Apr 18 2021 at 08:46)</a>:</h4>
<p><span class="user-mention silent" data-user-id="300586">Lukas Wirth</span> <a href="#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param/near/235025239">said</a>:</p>
<blockquote>
<p>I guess this is the problem with undocumented functions that have weird special case behaviours <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>
</blockquote>
<p>it's... not a weird special case behavior though? if you have <code>impl S</code>, it's an impl for <code>S</code>, not <code>&amp;S</code>. Removing the references automatically would be the weird special case</p>



<a name="235056927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235056927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235056927">(Apr 18 2021 at 08:53)</a>:</h4>
<p><code>Impl::all_for_type</code> actually does have some weird special-case behavior in that it strips references from the self type in trait impls (so the other way around, it'll return <code>impl T for &amp;S</code> if you give it just<code>S</code>), because it's currently mainly built for the impl search (the "N implementations" code lens on structs). It's not a good general abstraction :/</p>



<a name="235056988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235056988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235056988">(Apr 18 2021 at 08:54)</a>:</h4>
<p>it might actually make sense to add a separate function to return only all inherent impls for a type</p>



<a name="235059039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235059039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235059039">(Apr 18 2021 at 09:35)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> I'll do that as part of this patch ^__^</p>



<a name="235059331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235059331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235059331">(Apr 18 2021 at 09:40)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span>  I have a question: I'm working with generated AST nodes created using <code>make::&lt;node_kind&gt;</code>. I have a method I'd like to attach to an <code>Impl</code> -- is there a good way of doing that?</p>



<a name="235059358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235059358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235059358">(Apr 18 2021 at 09:41)</a>:</h4>
<p>I'm looking at <code>AssocItemList</code>, but not sure how to attach one node within another</p>



<a name="235059541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235059541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235059541">(Apr 18 2021 at 09:44)</a>:</h4>
<p>ohh, now seeing <code>Impl::with_assoc_item_list</code> which returns another <code>Impl</code></p>



<a name="235060028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235060028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235060028">(Apr 18 2021 at 09:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="129457">Florian Diebold</span> <a href="#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param/near/235056613">said</a>:</p>
<blockquote>
<p>it's... not a weird special case behavior though? if you have <code>impl S</code>, it's an impl for <code>S</code>, not <code>&amp;S</code>. Removing the references automatically would be the weird special case</p>
</blockquote>
<p>Right, I remembered this wrong, was thinking of the type fingerprints ignoring references</p>



<a name="235060944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235060944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235060944">(Apr 18 2021 at 10:08)</a>:</h4>
<p><span class="user-mention" data-user-id="211722">@Yoshua Wuyts</span> yeah, <code>with_assoc_item_list</code> would be the current way; there's also <span class="user-mention" data-user-id="133169">@matklad</span> 's new in-place editing infrastructure, with which you could have something like <code>impl.add(your_function)</code>, but you'd have to add that (there's not much there yet, you can see it in <code>edit_in_place.rs</code>)</p>



<a name="235061139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235061139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235061139">(Apr 18 2021 at 10:12)</a>:</h4>
<p>oh cool, thanks!</p>



<a name="235061156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235061156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235061156">(Apr 18 2021 at 10:12)</a>:</h4>
<p>hehe yeah I'm a bit hesitant to use the edit_in_place stuff right now -- so think I'll stick with manually constructing the list, and maybe refactor later</p>



<a name="235061166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235061166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235061166">(Apr 18 2021 at 10:13)</a>:</h4>
<p>(side note: getting real close to having all common paths covered on this assist!)</p>



<a name="235064879"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235064879" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235064879">(Apr 18 2021 at 11:21)</a>:</h4>
<p>Is there a good way to go from a <code>hir::Type</code> to an <code>ast::Path</code> -- e.g. I'm trying to find out where a type has been defined so I can insert an impl block after it.</p>



<a name="235064885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235064885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235064885">(Apr 18 2021 at 11:21)</a>:</h4>
<p>cc/ <span class="user-mention" data-user-id="300586">@Lukas Wirth</span></p>



<a name="235064973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235064973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235064973">(Apr 18 2021 at 11:23)</a>:</h4>
<p>I guess <code>Type::iterate_path_candidates</code> ?</p>



<a name="235064984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235064984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235064984">(Apr 18 2021 at 11:23)</a>:</h4>
<p>That's a good question</p>



<a name="235064997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235064997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235064997">(Apr 18 2021 at 11:24)</a>:</h4>
<p>I think iterate_path_candidates iterates the associated things of a type, so probably not what you want</p>



<a name="235065048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235065048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235065048">(Apr 18 2021 at 11:24)</a>:</h4>
<p>Ye that iterates the associated items</p>



<a name="235065067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235065067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235065067">(Apr 18 2021 at 11:24)</a>:</h4>
<p>ah right you can go with <code>ty.as_adt()</code> and i think then you can use <code>HasSource::source</code> on it like you did for <code>Impl</code> already to get the file and position of the item definition</p>



<a name="235065116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235065116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235065116">(Apr 18 2021 at 11:25)</a>:</h4>
<p>Basically that gives you the <code>Adt</code> of the type, if it represents ones. So you have to use that on the reference stripped type again</p>



<a name="235065183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235065183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235065183">(Apr 18 2021 at 11:26)</a>:</h4>
<p>cool, I'll give that a shot!</p>



<a name="235065263"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235065263" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235065263">(Apr 18 2021 at 11:28)</a>:</h4>
<p>Ah you have to match on the adt, <code>HasSource</code> is implemented for <code>Union</code>, <code>Enum</code> and <code>Struct</code> separately since the ast types differ.</p>



<a name="235066724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235066724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235066724">(Apr 18 2021 at 11:56)</a>:</h4>
<p>Realizing this is taking up a fair bit of time; going to call it quits for now. GitHub issue is here: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/8555#issuecomment-821979973">https://github.com/rust-analyzer/rust-analyzer/issues/8555#issuecomment-821979973</a></p>



<a name="235066740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235066740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235066740">(Apr 18 2021 at 11:56)</a>:</h4>
<p>Progress on this is here: <a href="https://github.com/rust-analyzer/rust-analyzer/compare/master...yoshuawuyts:whats-a-method-to-a-method-call">https://github.com/rust-analyzer/rust-analyzer/compare/master...yoshuawuyts:whats-a-method-to-a-method-call</a></p>



<a name="235066744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235066744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235066744">(Apr 18 2021 at 11:57)</a>:</h4>
<p>If someone would like to finish this up, please do!</p>



<a name="235104030"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235104030" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235104030">(Apr 18 2021 at 21:39)</a>:</h4>
<p>heh, guess I came back to this</p>



<a name="235104146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235104146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235104146">(Apr 18 2021 at 21:41)</a>:</h4>
<p><span class="user-mention" data-user-id="300586">@Lukas Wirth</span> what if we had an "edit_in_place" helper which could be: <code>edit_or_create_impl_block</code> for any <code>Type</code>.</p>



<a name="235104283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235104283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235104283">(Apr 18 2021 at 21:43)</a>:</h4>
<p>Would be reasonable to add I believe</p>



<a name="235104386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235104386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235104386">(Apr 18 2021 at 21:45)</a>:</h4>
<p>The question is how to handle receiving an edited impl vs receiving a fresh impl in the assists</p>



<a name="235104409"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235104409" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235104409">(Apr 18 2021 at 21:45)</a>:</h4>
<p>Since one would updated an old impl and the other would require to add an new impl node</p>



<a name="235104741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235104741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235104741">(Apr 18 2021 at 21:50)</a>:</h4>
<p>yeah - I don't think I fully understand inserting of nodes in the tree yet</p>



<a name="235104877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235104877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235104877">(Apr 18 2021 at 21:53)</a>:</h4>
<p>inserting nodes is in general a bit weird, I don't even remember how we do it right now. Thats probably also the reason why a lot of assists just insert via text range positions. Ideally most of that will become simpler/nicer to look at though now that we have opt-in mutable syntex trees</p>



<a name="235104973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235104973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235104973">(Apr 18 2021 at 21:55)</a>:</h4>
<p><em>nods</em></p>



<a name="235105167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105167">(Apr 18 2021 at 21:59)</a>:</h4>
<p>I guess I'm starting with the basics for this for now -- opened a new branch and adding two methods to <code>Impl</code>: <code>push_front</code> and <code>push_back</code></p>



<a name="235105177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105177">(Apr 18 2021 at 21:59)</a>:</h4>
<p>just to get the hang of mutable immutable trees</p>



<a name="235105228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105228">(Apr 18 2021 at 22:00)</a>:</h4>
<p>is there like, any reason why an <code>Impl</code> may not have an <code>AssocItemList</code>?</p>



<a name="235105369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105369">(Apr 18 2021 at 22:02)</a>:</h4>
<p>To accommodate for incomplete syntax trees</p>



<a name="235105379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105379">(Apr 18 2021 at 22:02)</a>:</h4>
<p>syntax errors and the like can cause that</p>



<a name="235105429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105429">(Apr 18 2021 at 22:03)</a>:</h4>
<p>I don't think there's much point in having no list vs. an empty list though</p>



<a name="235105447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105447">(Apr 18 2021 at 22:03)</a>:</h4>
<p>if the user was to only type <code>impl Foo</code> we'd get an <code>Impl</code> node that doesnt have an <code>AssocItemList</code>  for example</p>



<a name="235105459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105459">(Apr 18 2021 at 22:03)</a>:</h4>
<p>an empty list has braces though, no list does not</p>



<a name="235105509"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105509" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105509">(Apr 18 2021 at 22:04)</a>:</h4>
<p>since the braces belong the <code>AssocItemlist</code></p>



<a name="235105527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105527">(Apr 18 2021 at 22:04)</a>:</h4>
<p>ah, gotcha!</p>



<a name="235105545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105545">(Apr 18 2021 at 22:05)</a>:</h4>
<p>oh btw, rough outline still -- but if this is right I think this will turn out real nice to work with!</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="n">ast</span>::<span class="n">Impl</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Push a node to the front of the impl block.</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">push_front</span><span class="p">(</span><span class="o">&amp;</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">adt</span>: <span class="nc">ast</span>::<span class="n">Adt</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">l_curly</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">assoc_item_list</span><span class="p">().</span><span class="n">unwrap</span><span class="p">().</span><span class="n">l_curly_token</span><span class="p">().</span><span class="n">unwrap</span><span class="p">();</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">position</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Position</span>::<span class="n">after</span><span class="p">(</span><span class="n">l_curly</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="n">ted</span>::<span class="n">insert</span><span class="p">(</span><span class="n">position</span><span class="p">,</span><span class="w"> </span><span class="n">adt</span><span class="p">.</span><span class="n">syntax</span><span class="p">());</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="235105627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105627">(Apr 18 2021 at 22:06)</a>:</h4>
<p>I imagine you are taking inspiration from whats already implemented for other things in <code>edit_in_place</code> right? Thats gonna be nice to have for sure</p>



<a name="235105655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105655">(Apr 18 2021 at 22:06)</a>:</h4>
<p>heh, yeah a little bit ^^ -- like you said there's really not much</p>



<a name="235105668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105668">(Apr 18 2021 at 22:07)</a>:</h4>
<p><span class="user-mention silent" data-user-id="300586">Lukas Wirth</span> <a href="#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param/near/235105509">said</a>:</p>
<blockquote>
<p>since the braces belong the <code>AssocItemlist</code></p>
</blockquote>
<p>ah okay, then it makes sense</p>



<a name="235105698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105698">(Apr 18 2021 at 22:08)</a>:</h4>
<p>hmmm, what if we had like a "heal" method for the various AST types?</p>



<a name="235105747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105747">(Apr 18 2021 at 22:08)</a>:</h4>
<p>e.g. a quick in-place edit that would fill out missing curlies, tokens, etc.</p>



<a name="235105789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105789">(Apr 18 2021 at 22:08)</a>:</h4>
<p>could be one way to get rid of the unwraps we have above</p>



<a name="235105804"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105804" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105804">(Apr 18 2021 at 22:09)</a>:</h4>
<p>(but maybe that's over-abstracting right now haha)</p>



<a name="235105860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105860">(Apr 18 2021 at 22:10)</a>:</h4>
<p>I feel like thats too abstract ye</p>



<a name="235105882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105882">(Apr 18 2021 at 22:10)</a>:</h4>
<p>haha yeahh</p>



<a name="235105891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105891">(Apr 18 2021 at 22:10)</a>:</h4>
<p>for that unwrap up there you could maybe instead have an inplace edit function for <code>get_or_create_assoc_item_list</code></p>



<a name="235105913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105913">(Apr 18 2021 at 22:11)</a>:</h4>
<p>similar to <code>GenericParamsOwnerEdit::get_or_create_where_clause</code></p>



<a name="235105967"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105967" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105967">(Apr 18 2021 at 22:12)</a>:</h4>
<p>Though matklad would certainly know better here given he has the grande vision of of this api <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span> especially as I havent dug into it yet myself</p>



<a name="235105972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235105972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235105972">(Apr 18 2021 at 22:12)</a>:</h4>
<p>aside from porting one small assist over</p>



<a name="235107634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235107634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235107634">(Apr 18 2021 at 22:44)</a>:</h4>
<p>Okay, breaking this up into a few smaller steps. First PR out: <a href="https://github.com/rust-analyzer/rust-analyzer/pull/8568">https://github.com/rust-analyzer/rust-analyzer/pull/8568</a></p>



<a name="235108614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235108614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235108614">(Apr 18 2021 at 23:01)</a>:</h4>
<p>I'll take a proper look tomorrow but one thing I saw is that you are pushing <code>Adt</code>s as items into the impl. That doesn't seem right.</p>



<a name="235108679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235108679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235108679">(Apr 18 2021 at 23:02)</a>:</h4>
<p>You want to push <code>AssocItem</code>s in there</p>



<a name="235108860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235108860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235108860">(Apr 18 2021 at 23:04)</a>:</h4>
<p>gotcha</p>



<a name="235108997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235108997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235108997">(Apr 18 2021 at 23:07)</a>:</h4>
<p>yeah, think it's bed time for me as well -- let's pick this back up again tomorrow ^^</p>



<a name="235108998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/get%20a%20module%20from%20a%20%60self%60%20param/near/235108998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/get.20a.20module.20from.20a.20.60self.60.20param.html#235108998">(Apr 18 2021 at 23:07)</a>:</h4>
<p>thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>